This repository has been archived by the owner on Feb 2, 2023. It is now read-only.
/
examples-frompapers-computing with neural synchrony-olfaction_Fig11B_olfaction_stdp_learning.txt
143 lines (115 loc) · 4.12 KB
/
examples-frompapers-computing with neural synchrony-olfaction_Fig11B_olfaction_stdp_learning.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
.. currentmodule:: brian
.. index::
pair: example usage; NeuronGroup
pair: example usage; run
pair: example usage; network_operation
pair: example usage; EventClock
pair: example usage; Connection
pair: example usage; SpikeMonitor
pair: example usage; exp
pair: example usage; save
pair: example usage; STDP
.. _example-frompapers-computing with neural synchrony-olfaction_Fig11B_olfaction_stdp_learning:
Example: Fig11B_olfaction_stdp_learning (frompapers/computing with neural synchrony/olfaction)
==============================================================================================
Brette R (2012). Computing with neural synchrony. PLoS Comp Biol. 8(6): e1002561. doi:10.1371/journal.pcbi.1002561
------------------------------------------------------------------------------------------------------------------
Figure 11B. Learning to recognize odors.
(long simulation)
Caption (Fig. 11B). After learning, responses
of postsynaptic neurons, ordered by tuning ratio, to odor A (blue) and odor B (red),
with an increasing concentration (0.1 to 10, where 1 is odor
concentration in the learning phase).
After this script, run the other file: Fig11B_olfaction_stdp_testing.py.
::
from brian import *
from params import *
from brian.experimental.connectionmonitor import *
import numpy
bmin,bmax=-7,-1
def odor(N):
# Returns a random vector of binding constants
return 10**(rand(N)*(bmax-bmin)+bmin)
def hill_function(c,K=1.,n=3.):
'''
Hill function:
* c = concentration
* K = half activation constant (choose K=1 for relative concentrations)
* n = Hill coefficient
'''
return (c**n)/(c**n+K**n)
N=5000 # number of receptors
seed(31415) # Get the same neurons every time
intensity=3000.
# Odor plumes
tau_plume=75*ms
eq_plumes='''
dx/dt=-x/tau_plume+(2./tau_plume)**.5*xi : 1
y=clip(x,0,inf) : 1
'''
plume=NeuronGroup(1,model=eq_plumes) # 1 odor
# Receptor neurons
Fmax=40*Hz # maximum firing rate
tau=20*ms
Imax=1/(1-exp(-1/(Fmax*tau))) # maximum input current
eq_receptors='''
dv/dt=(Imax*hill_function(c)-v)/tau : 1
c : 1 # concentrations (relative to activation constant)
'''
receptors=NeuronGroup(N,model=eq_receptors,threshold=1,reset=0)
@network_operation
def odor_to_nose():
# Send odor plume to the receptors
receptors.c=I1*c1*clip(plume.x[0],0,Inf)
odors=[odor(N),odor(N)] # two odors
c1=odors[0]
stimuli=[]
# A random odor is presented every 200 ms
@network_operation(clock=EventClock(dt=200*ms))
def change_odor():
global c1
nodor=randint(len(odors))
c1=odors[nodor]
stimuli.append((float(defaultclock.t),float(nodor)))
# Decoder neurons
M=30
eq_decoders='''
dv/dt=-v/taud + sigma*(2/taud)**.5*xi : 1
'''
decoders=NeuronGroup(M,model=eq_decoders,threshold=1,reset=0)
S2=SpikeMonitor(decoders)
# Random synapses
syn=Connection(receptors,decoders,'v',sparseness=Nsynapses*1./N,weight=w0)
# STDP
eqs_stdp='''
dApre/dt=-Apre/tau_pre : 1
Apost : 1
'''
pre='''
Apre+=a_pre
#w+=0
'''
post='''
Apost+=0
w+=Apre+b_post*w
'''
stdp=STDP(syn,eqs_stdp,pre=pre,post=post,wmax=Inf)
MC=ConnectionMonitor(syn,store=True,clock=EventClock(dt=record_period))
@network_operation(EventClock(dt=IP_period))
def intrinsic_plasticity(): # synaptic scaling
# Increases weights of all synapses
syn.W.alldata+=syn.W.alldata*IP_rate*IP_period
# Record the evolution of weights
weights=[]
@network_operation(EventClock(dt=record_period))
def recordW():
Z=syn.W[:,0].copy()
weights.append(Z)
I1=intensity
print "Started"
run(duration,report="text")
# Save data
wsave=[(t,M.todense()) for (t,M) in MC.values]
numpy.save("weights.npy",array(zip(*wsave)[1])) # 3D array (t,i,j)
numpy.save("spikesout.npy",array(S2.spikes))
numpy.save("stimuli.npy",array(stimuli))